package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.zr.model.Employee;
import com.zr.service.OverServiceWW;
import com.zr.service.SelectDateService;
import com.zr.serviceImpl.OverServiceImplWW;
import com.zr.serviceImpl.SelectDateServiceImpl;

public class OverFuncControllerWW extends HttpServlet {

	OverServiceWW overservice = new OverServiceImplWW();
	SelectDateService selcdao = new SelectDateServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
	 
		int eid =Integer.parseInt((String) session.getAttribute("eid")) ;
		String date = req.getParameter("date");
		
		String wcontent = req.getParameter("wcontent");
		String opinion = req.getParameter("opinion");
		String btime = req.getParameter("btime");
		String etime = req.getParameter("etime");
		
		PrintWriter pw = resp.getWriter();	
		
		 JSONArray j=selcdao.selectdateByEid(eid);
		  j.getJSONObject(0).get("date");//取到值
		
		  if(date.equals(j.getJSONObject(0).get("date"))){
			  
			  pw.write("0");
		  }else{
			  boolean flag = overservice.overtimeApplication(date, btime, etime, wcontent, opinion, eid);
			  if(flag==true){
					pw.write("1");
				}else{
					pw.write("0");
				}	
				pw.flush();
				pw.close();	
		  }
		  	
	}
}

